<?php
namespace app\controller;

use app\BaseController;
use think\facade\Env;
use think\facade\Db;
use app\model\Goods;
use think\View;
class Index extends BaseController
{
    public function index()
    {
        $db=new Goods();
        $select = $db->select();
        print_r($select);
        //$query = Db::query('select * from shop_goods');
        //print_r($query);
        //$query = Db::table('shop_goods')->find(1);
        //$query = Db::name('goods')->find(2);
        //$select = Db::table('shop_goods')->select();
        //$value = Db::table('shop_goods')->value('title');
        //$column = Db::table('shop_goods')->column('title','id');
        //$data = ['cat'=>'1','title'=>'日系小浪漫与温暖羊毛针织拼接网纱百褶中长收腰连衣裙','price'=>'1598.35','add_time'=>1576080000];
        //$insert = Db::table('shop_goods')->insert($data);
        //$data = ['cat'=>'1','title'=>'针织毛衣连衣裙2019秋冬新款气质宽松羊毛长袖中长款休闲打底裙女','price'=>'690.00','add_time'=>1576080000];
        //$insert = Db::table('shop_goods')->insertGetId($data);
        /*$data = [
            ['cat'=>'1','title'=>'秋冬加厚连衣裙女超长款宽松羊绒衫高领套头过膝毛衣百搭针织长裙','price'=>'658.00','add_time'=>1576080000],
            ['cat'=>'1','title'=>'2019新款秋冬慵懒风宽松毛衣针织连衣裙复古港味网红两件套','price'=>'408.00','add_time'=>1576080000],
            ['cat'=>'2','title'=>'男士长袖t恤秋季圆领黑白体恤T 纯色上衣服打底衫男装','price'=>'99.00','add_time'=>1576080000]
        ];
        $insert = Db::table('shop_goods')->insertAll($data);
        //return Db::getlastSQL();
        return $insert;
        $data = ['price'=>'68'];
        $update = Db::table('shop_goods')->where('id',23)->update($data);
        $inc = Db::table('shop_goods')->where('id',23)->inc('stock',5)->update();
        print_r($inc);
        $delete = Db::table('shop_goods')->where('id','=',24)->delete();
        print_r($delete);
        $select = Db::table('shop_goods')->where('id','>=','25')->select();
        return json($select);
        $select = Db::table('shop_goods')
            ->where('id','>','3')
            ->where('id','<','26')
            ->select();
        print_r($select->toArray());
        $select = Db::table('shop_goods')->where('id','between','23,26')->select();
        print_r($select->toArray());*/
        //$select = Db::table('shop_goods')->where('title','like','连衣裙%')->select();
        //$select = Db::name('goods')->where('title','like','连衣裙%')->select();
        /*
        $select = Db::table('shop_goods')
                    //->field('title,price,discount as 折扣')
                    ->field([
                        'id',
                        'title',
                        'price',
                        'discount'=>'zhekou'
                    ])  
                    //->order('price','DESC')
                    ->order('id','ASC')
                    //->limit(0,4)
                    ->page(0,3)
                    ->select();
        print_r($select->toArray());
        */
        //$select = Db::table('shop_goods')->count();
        //$select = Db::table('shop_goods')->max('price');
        //$select = Db::table('shop_goods')->min('price');
        //$select = Db::table('shop_goods')->avg('price');
        //$select = Db::table('shop_goods')->sum('price');
        /*
        $select = Db::table('shop_goods')
                        ->field('cat,count(cat)')
                        ->group('cat')
                        ->having('cat=1')
                        ->select();
        
        $select = Db::table('shop_goods')
                    ->alias('a')
                    ->join('shop_cat b','a.cat=b.id')
                    ->field('a.id,title')
                    ->select();
        //print_r($select->toArray());
        return Db::getlastSQL();*/
    }

    public function hello($name = 'ThinkPHP6')
    {
        return 'hello,' . $name;
    }
    public function read($name = '李四'){
        return $name.'读书11';
    }
    public function say()
    {
        View::assign('name','ThinkPHP');
        View::assign('email','thinkphp@qq.com');

        View::assign([
            'name2'  => 'ThinkPHP2',
            'email2' => 'thinkphp2@qq.com'
        ]);

        return View::fetch();
    }
}
